﻿using B.S.Data.MES.API.Applications.Management.SteamApplication.Command.RoleCommand;
using B.S.Domain.Accounts;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.Management.SteamApplication.CommandHandler.RoleCommandHandler
{
    public class RoleDelCommandHandler : IRequestHandler<RoleDelCommand, APIRequst<int>>
    {
        public RoleDelCommandHandler(IBaseRepository<RoleEntty> roleRepository)
        {
            RoleRepository = roleRepository;
        }

        public IBaseRepository<RoleEntty> RoleRepository { get; }

        public Task<APIRequst<int>> Handle(RoleDelCommand request, CancellationToken cancellationToken)
        {
            var path = RoleRepository.GetAll().FirstOrDefault(a => a.RoleId == request.Id);
            if (path == null)

                return Task.FromResult(new APIRequst<int> { Code = RequstCode.成功, Msg = "删除失败，角色不存在！", Data = 0 });
            else
                path.DeleteName = request.Name;
            path.isDel = true;
            RoleRepository.Update(path);
            return Task.FromResult(new APIRequst<int> { Code = RequstCode.成功, Msg = "删除成功！", Data = 1 });

        }
    }
}
